import axios from 'axios';

const service = axios.create({
    baseURL: '/', // 接口请求地址
    timeout: 1500000, // 请求超时时间
    headers: {
      'Content-Type': 'multipart/form-data;charset=UTF-8',
    },
    withCredentials: false,
  });
  
  // service.defaults.transformRequest = data => JSON.stringify(data);
  service.interceptors.request.use(
    Config => {
      let token = localStorage.getItem('satoken');
      if (token != null) {
        token = token.replace(/\"/g, '');
      }
      token & (Config.headers.satoken = token);
      return Config;
    },
    error => {
      return Promise.reject(error);
    }
  );
  
  service.interceptors.response.use(response => {
    const { code, data, msg } = response.data;
    if (code == 'success' || 200) {
      return data;
    } else if (code == 'error' || 'exception') {
      Modal.message({ message: msg, status: 'info' });
    } else if (code == 'warning') {
      Modal.message({ message: msg, status: 'warning' });
    } else {
      Modal.message({ message: '请求失败！！！', status: 'error' });
    }
  });
  
  export default service;
  